package com.arthur.controller;

import com.arthur.bean.Product;
import com.arthur.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@Controller
public class ProductDetailController {
    @Autowired
    @Qualifier("userService")
    private UserService userService;
    @RequestMapping("/ProductDetailController")
    @ResponseBody
    protected Map productInfoList (HttpServletRequest request, HttpServletResponse response)throws Exception{
        Map<String, Object> objectMap = new HashMap<>();
        response.setCharacterEncoding("UTF-8");
        String productname=request.getParameter("productname");
        System.out.println(productname+"aaa");
        Product temp_productinfo = userService.fetchProductinfoByName(productname);
        if(temp_productinfo==null){
            objectMap.put("result","0");
        }else{
            objectMap.put("result","1");
            objectMap.put("productInfo",temp_productinfo);
        }

        return objectMap;
    }


}
